package com.liang.gulimall.search.controller;

import com.liang.gulimall.search.service.MallSearchService;
import com.liang.gulimall.search.vo.SearchParamVo;
import com.liang.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.io.IOException;

@Controller
public class SearchController {
    @Autowired
    MallSearchService mallSearchService;

    /**
     * MVC自动将传递过来的条件封装成SearchParamVo对象
     * @param paramVo
     * @return
     */
    @GetMapping("list.html")
    public String toListPage(SearchParamVo paramVo, Model model){
        SearchResult result= null;
        try {
            result = mallSearchService.search(paramVo);
        } catch (IOException e) {
            e.printStackTrace();
        }
        model.addAttribute("result",result);
        return "list";
    }
}
